#-------------------------------------------------------------------------------
# Name:        GObject
# Purpose:     Base class for all objects in map-space
#
# Author:      Lorien
#
# Created:     31.08.2011
# Copyright:   (c) Lorien 2011
# Licence:     Private
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import pygame, os
import transform
from consts import *


class GObject(pygame.sprite.Sprite):
    def __init__(self, position, map_worker):
        pygame.sprite.Sprite.__init__(self)
        self.image = False
        self.map_worker = map_worker
        self.position = position
        self._x, self._y = position #screen-space coords
        self.rect = None

    # property list
    #---------------------
    def setx(self, value):
        self.rect.left = int(value * transform.scaleX)
        self._x = value
        self.position = (self.rect.left, self.position[1])


    def sety(self, value):
        self.rect.top = int(value * transform.scaleY)
        self._y = value
        self.position = (self.position[0], self.rect.top)


    x = property(lambda self: self._x, setx)
    y = property(lambda self: self._y, sety)

    # --------------------
    # end of property list

    def update(self, time_pass):
        pass

    def draw(self, screen, pos=None):
        if self.image:
            # pos is real position (not game grid position)
            if pos:
                screen.blit(self.image, self.image.get_rect(center=pos))
            else:
                screen.blit(self.image, self.rect)

    def loadGraphics(self, filename):
        #Graphics
        image_patch = os.path.join(IMAGES_PATH, filename)
        self.image = pygame.image.load(image_patch).convert_alpha()
        self.image = pygame.transform.scale(self.image,
                                            (int(self.width * transform.scaleX), int(self.height * transform.scaleY)))

        if not self.rect:
            self.rect = self.image.get_rect(topleft=self.position)
            self.rect = transform.getRealRect(self.rect)

    def isMonster(self):
        return False


